<template>
  <div class="pagebox">
    <crumbs @goBack="goBack" :superiorMenu="['物品管理']" currentMenu="物品" style="margin-bottom: 12px"></crumbs>
    <a-card :bordered="false" size="small">
      <a-tabs default-active-key="0" @change="changeCurrent">
        <a-tab-pane v-for="row in typeListTab" :key="row.value" :tab="row.title"> </a-tab-pane>
      </a-tabs>
      <div class="topBox">
        <div>
          <a-button @click="handleShowFilter" icon="filter" style="margin-right: 10px">
            筛选 <span style="color: #1890ff; margin-left: 5px">{{ realFilterNum }}</span></a-button
          >
          <a-button @click="showColumn" icon="unordered-list" style="margin-right: 10px"> 设置列 </a-button>
        </div>
        <div style="display: flex">
          <PubImport
            @updateParentData="updateParentData"
            ref="PubImport"
            tableCode="WMS_GOODS"
            modelName="物品导入模板"
            style="margin-right: 10px"
          />
          <a-button type="primary" @click="add"> +新建 </a-button>
        </div>
      </div>
      <a-table
        :key="tableKey"
        row-key="id"
        :columns="columns"
        :data-source="tableData"
        :pagination="false"
        :scroll="{ x: scrollX, y: 'calc(100vh - 400px)' }"
        :components="drag(columns, 'GOODS_MANAGEMENT_LIST')"
        :row-selection="{ selectedRowKeys: selectedRowKeys, columnTitle: ' ', onChange: onSelectChange }"
        @change="tableChange"
      >
        <span slot="goodsCode" :title="text" slot-scope="text, record" class="btn-text" @click="handleDetail(record)">
          {{ text }}
        </span>
        <!-- <span slot="goodsName" :title="text" slot-scope="text, record">
          {{  text }}
        </span>
        <span slot="spec" :title="text" slot-scope="text, record">
          {{  text }}
        </span> -->
        <!-- <span slot="goodsCode" slot-scope="text, record"
          ><a @click="handleDetail(record)">{{ record.goodsCode }}</a></span
        > -->
        <span slot="category" :title="record.categoryText" slot-scope="text, record">{{ record.categoryText }}</span>
        <!-- 输入框搜索 -->
        <div
          slot="searchDropdown"
          slot-scope="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"
          class="searchWorkOreder"
        >
          <a-input
            :placeholder="checkPlaceholder(column.dataIndex)"
            v-model="tableFilterForm[column.dataIndex]"
            style="width: 188px; display: block"
          />
          <a-button
            type="primary"
            style="width: 80px; margin-left: 20px; display: block"
            @click="() => pubSearch(confirm, column.dataIndex, clearFilters)"
          >
            搜索
          </a-button>
        </div>
        <a-icon
          slot="searchIcon"
          slot-scope="filtered"
          type="search"
          :style="{ color: filtered ? '#108ee9' : undefined }"
        />
        <!-- 选择搜索 -->
        <div slot="selectDropdown" slot-scope="{ confirm, clearFilters, column }" class="searchWorkOreder">
          <!-- <a-select
            v-if="column.dataIndex == 'category'"
            mode="multiple"
            :placeholder="checkPlaceholder(column.dataIndex)"
            style="width: 200px"
            v-model="tableFilterForm[column.dataIndex]"
          >
            <a-select-option v-for="item in statusList" :key="item.value" :value="item.value">
              {{ item.label }}
            </a-select-option>
          </a-select> -->
          <a-tree-select
            v-if="column.dataIndex == 'category'"
            allow-clear
            v-model="tableFilterForm[column.dataIndex]"
            :multiple="false"
            placeholder="请选择"
            style="width: 200px"
            :tree-data="treeData"
            :replaceFields="replaceFields"
            :show-checked-strategy="SHOW_PARENT"
            search-placeholder="请选择"
            @change="treeChange"
          />
          <a-select
            v-if="column.dataIndex == 'type'"
            mode="multiple"
            :placeholder="checkPlaceholder(column.dataIndex)"
            style="width: 200px"
            v-model="tableFilterForm[column.dataIndex]"
          >
            <a-select-option v-for="item in typeList" :key="item.value" :value="item.value">
              {{ item.title }}
            </a-select-option>
          </a-select>
          <a-button
            type="primary"
            style="width: 80px; margin-left: 20px; display: block"
            @click="() => pubSearch(confirm, column.dataIndex, clearFilters)"
          >
            搜索
          </a-button>
        </div>
        <a-icon
          slot="selectIcon"
          slot-scope="filtered"
          type="filter"
          :style="{ color: filtered ? '#108ee9' : undefined }"
        />
        <span slot="type" slot-scope="text, record">
          {{ record.typeText }}
        </span>
        <span slot="actions" slot-scope="text, record">
          <!-- <a @click="handleDetail(record)">详情</a> -->
          <!-- <a-divider type="vertical" /> -->
          <a v-if="record.flowStatus == 'RUNNING' && record.createBy == loginUser" @click="handleWithdraw(record)"
            >撤回</a
          >
          <a v-if="record.status == 'effective'" @click="handleEdit(record)">编辑</a>
          <a-divider v-if="record.status == 'effective'" type="vertical" />
          <a v-if="record.flowStatus != 'RUNNING'" @click="handleDelete(record)">删除</a>
        </span>
      </a-table>
    </a-card>
    <div
      class="uni-card"
      :style="{
        position: 'fixed',
        bottom: 0,
        right: 0,
        zIndex: 2,
        left: collapsed ? '79px' : '208px',
        background: '#fff',
        paddingLeft: '68px',
      }"
    >
      <div style="display: inline-block">
        <a-checkbox :indeterminate="listIndeterminate" :checked="listCheckAll" @change="onCheckAllChange"></a-checkbox>
        <span style="margin-left: 8px">
          {{ `已选 ${selectedRowKeys.length}/${total} 项` }}
          <span class="pubColor" @click="clearArr" style="margin: 0 10px">清空</span>
          <span @click="handleDelete(selectedRowKeys)" class="pubColor" style="margin: 0 10px">批量删除</span>
        </span>
      </div>
      <div style="display: inline-block; float: right">
        <a-pagination
          :total="total"
          v-model="current"
          :page-size-options="pageSizeOptions"
          :page-size="pageSize"
          @change="onChangePage"
          @showSizeChange="onShowSizeChange"
          show-quick-jumper
          show-size-changer
        />
      </div>
    </div>
    <SetColumn
      columnName="设置列"
      ref="SetColumn"
      v-if="showSetColumn"
      @sureBtn="sureBtn"
      @cancelBtn="showSetColumn = false"
    />
    <!-- 筛选抽屉 -->
    <a-drawer width="500" :closable="true" :visible="showFilter" @close="closeFilter">
      <div class="filter-body">
        <div slot="title" class="uni-card filter-tit">
          筛选 <span class="filter-num">{{ filteredNums }}</span>
        </div>
        <div class="uni-card" v-if="filteredNums > 0" style="background: #fff">
          <div v-for="(item, i) in filteredList" :key="i" v-show="checkShow(item.text)" class="tag-wrap">
            <span class="filter-tag" @click="delFiltered(item.key)">
              <span class="tag-text">{{ `${item.title}：${item.text}` }}</span>
              <a-icon type="close" style="float: right" />
            </span>
          </div>
        </div>
        <div style="overflow-y: scroll; flex: 1; padding: 0">
          <div class="uni-card" style="background: #fff">
            <a-form-model ref="ruleForm" layout="vertical" :model="filterForm">
              <a-form-model-item label="物品编号">
                <a-input v-model="filterForm.goodsCode" placeholder="请输入" />
              </a-form-model-item>
              <a-form-model-item label="物品名称">
                <a-input v-model="filterForm.goodsName" placeholder="请输入" />
              </a-form-model-item>
              <a-form-model-item label="规格">
                <a-input v-model="filterForm.spec" placeholder="请输入" />
              </a-form-model-item>
              <a-form-model-item label="分类">
                <!-- <a-select mode="multiple" placeholder="请选择" v-model="filterForm.category">
                  <a-select-option v-for="item in statusList" :key="item.value" :value="item.value">
                    {{ item.label }}
                  </a-select-option>
                </a-select> -->
                <a-tree-select
                  allow-clear
                  v-model="filterForm.category"
                  :multiple="false"
                  placeholder="请选择"
                  style="width: 100%"
                  :tree-data="treeData"
                  :replaceFields="replaceFields"
                  :show-checked-strategy="SHOW_PARENT"
                  search-placeholder="请选择"
                  @change="treeChange"
                />
              </a-form-model-item>
              <a-form-model-item label="类型">
                <a-select mode="multiple" placeholder="请选择" v-model="filterForm.type">
                  <a-select-option v-for="item in typeList" :key="item.value" :value="item.value">
                    {{ item.title }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
              <!-- <a-form-model-item label="审核状态">
                <a-select mode="multiple" placeholder="请选择" v-model="filterForm.flowStatus">
                  <a-select-option value="RUNNING">审批中</a-select-option>
                  <a-select-option value="TERMINATED">被终止</a-select-option>
                  <a-select-option value="AGREE">审批通过</a-select-option>
                  <a-select-option value="REFUSE">审批拒绝</a-select-option>
                  <a-select-option value="CANCELED">取消</a-select-option>
                </a-select>
              </a-form-model-item> -->
            </a-form-model>
          </div>
        </div>
        <div class="footer-submit">
          <a-button class="margin-btn" @click="resetFilter">重置</a-button>
          <a-button type="primary" @click="handleFilter">确定</a-button>
        </div>
      </div>
    </a-drawer>
    <windowForm ref="windowForm" @refresh="pubSearch(() => {})"></windowForm>
    <windowDetail ref="windowDetail"></windowDetail>
  </div>
</template>
<script>
import { getAction, httpAction, deleteAction } from '@/api/manage'
import { goodsList, categoryGetTree, goodsLogicDelBatch, goodsLogicDel, getDictModel } from '@/api/goodsManagement'
import { getNewColumns, subStrText } from '@/utils/util'
import { columns, allColumn } from '@/views/workManagement/workOrder/allColumn.js'
import SetColumn from '@/pubComponent/SetColumn.vue'
import crumbs from '@/components/crumbs.vue'
import { mapState } from 'vuex'
import { TreeSelect } from 'ant-design-vue'
import { API } from '@/api/requestFzs'
import { getEnableOne } from '@/api/api'
import PubImport from '@/components/pubBtn/PubImport.vue'
import tableDragResize from '@/mixins/tableDragResize'

const SHOW_PARENT = TreeSelect.SHOW_PARENT
const treeData = []
// 表头
/* 打开设置列面板123 */
const columnsValue = [
  {
    title: '物品编号',
    ellipsis: true,
    width: 180,
    dataIndex: 'goodsCode',
    scopedSlots: {
      filterDropdown: 'searchDropdown',
      filterIcon: 'searchIcon',
      customRender: 'goodsCode',
    },
  },
  {
    title: '物品名称',
    width: 120,
    ellipsis: true,
    dataIndex: 'goodsName',
    scopedSlots: {
      filterDropdown: 'searchDropdown',
      filterIcon: 'searchIcon',
      customRender: 'goodsName',
    },
  },
  {
    title: '规格',
    width: 120,
    ellipsis: true,
    dataIndex: 'spec',
    scopedSlots: {
      filterDropdown: 'searchDropdown',
      filterIcon: 'searchIcon',
      customRender: 'spec',
    },
  },
  {
    title: '分类',
    dataIndex: 'category',
    ellipsis: true,
    width: 100,
    scopedSlots: {
      filterDropdown: 'selectDropdown',
      filterIcon: 'selectIcon',
      customRender: 'category',
    },
  },
  {
    title: '类型',
    dataIndex: 'type',
    width: 100,
    ellipsis: true,
    scopedSlots: {
      filterDropdown: 'selectDropdown',
      filterIcon: 'selectIcon',
      customRender: 'type',
    },
  },
  {
    title: '审核状态',
    dataIndex: 'flowStatusName',
    ellipsis: true,
    width: 100,
    // scopedSlots: {
    //   filterDropdown: 'selectDropdown',
    //   filterIcon: 'selectIcon',
    //   customRender: 'flowStatus',
    // },
  },
  {
    title: '状态',
    dataIndex: 'statusText',
    ellipsis: true,
    width: 100,
    // scopedSlots: {
    //   filterDropdown: 'selectDropdown',
    //   filterIcon: 'selectIcon',
    //   customRender: 'flowStatus',
    // },
  },
  // {
  //   fixed: 'right',
  //   title: '操作',
  //   // align: 'left',
  //   dataIndex: 'actions',
  //   scopedSlots: { customRender: 'actions' },
  // },
]
const actionArr = [
  {
    fixed: 'right',
    title: '操作',
    width: 120,
    // align: 'left',
    dataIndex: 'actions',
    scopedSlots: { customRender: 'actions' },
  },
]
export default {
  components: {
    crumbs,
    SetColumn,
    PubImport,
    windowForm: (resolve) => require(['@/views/warehouseManagement/goodsManagement/goodsManagementAdd'], resolve),
    windowDetail: (resolve) => require(['@/views/warehouseManagement/goodsManagement/goodsManagementDetail'], resolve),
  },
  mixins: [tableDragResize],
  data() {
    return {
      columnsValue,
      typeListTab: [], //头部tab
      // 树选择
      subStrText,
      value: '',
      treeData,
      SHOW_PARENT,
      treeSelectLael: '',
      replaceFields: {
        children: 'children',
        title: 'name',
        key: 'id',
        value: 'id',
      },
      tableData: [],
      selectedRowKeys: [],
      selectArr: [],
      //全选按钮
      listIndeterminate: false,
      listCheckAll: false,
      current: 1,
      total: 0,
      pageSize: 10,
      pageSizeOptions: ['10', '20', '30', '40', '50'],
      typeList: [],
      columns: [
        {
          title: '物品编号',
          ellipsis: true,
          width: 180,
          dataIndex: 'goodsCode',
          scopedSlots: {
            filterDropdown: 'searchDropdown',
            filterIcon: 'searchIcon',
            customRender: 'goodsCode',
          },
        },
        {
          title: '物品名称',
          ellipsis: true,
          width: 120,
          dataIndex: 'goodsName',
          scopedSlots: {
            filterDropdown: 'searchDropdown',
            filterIcon: 'searchIcon',
            customRender: 'goodsName',
          },
        },
        {
          title: '规格',
          width: 120,
          ellipsis: true,
          dataIndex: 'spec',
          scopedSlots: {
            filterDropdown: 'searchDropdown',
            filterIcon: 'searchIcon',
            customRender: 'spec',
          },
        },
        {
          title: '分类',
          dataIndex: 'category',
          ellipsis: true,
          width: 100,
          scopedSlots: {
            filterDropdown: 'selectDropdown',
            filterIcon: 'selectIcon',
            customRender: 'category',
          },
        },
        {
          title: '类型',
          dataIndex: 'type',
          ellipsis: true,
          width: 100,
          scopedSlots: {
            filterDropdown: 'selectDropdown',
            filterIcon: 'selectIcon',
            customRender: 'type',
          },
        },
        {
          title: '审核状态',
          dataIndex: 'flowStatusName',
          ellipsis: true,
          width: 100,
          // scopedSlots: {
          //   filterDropdown: 'selectDropdown',
          //   filterIcon: 'selectIcon',
          //   customRender: 'flowStatusName',
          // },
        },
        {
          title: '状态',
          dataIndex: 'statusText',
          ellipsis: true,
          width: 100,
          // scopedSlots: {
          //   filterDropdown: 'selectDropdown',
          //   filterIcon: 'selectIcon',
          //   customRender: 'flowStatusName',
          // },
        },
        // {
        //   fixed: 'right',
        //   title: '操作',
        //   width: 120,
        //   // align: 'left',
        //   dataIndex: 'actions',
        //   scopedSlots: { customRender: 'actions' },
        // },
      ],
      tableFilterForm: {}, //表头输入搜索
      realFilterForm: {},
      filteredFormLable: {
        goodsCode: '物品编号',
        goodsName: '物品名称',
        spec: '规格',
        category: '分类',
        type: '类型',
        spec: '规格',
        // flowStatus: '状态',
      },
      // 筛选
      showFilter: false, // 筛选抽屉
      filterForm: {
        goodsCode: '', //物品编号
        goodsName: '', //物品名称
        category: [], //分类
        type: [], //类型
        spec: '', //规格
        // flowStatus: [], //审核状态
      },
      statusList: [
        {
          label: '未开始',
          value: 'notStarted',
        },
        {
          label: '生产中',
          value: 'inProduction',
        },
        {
          label: '已作废',
          value: 'abolished',
        },
        {
          label: '已完成',
          value: 'completed',
        },
      ],

      showSetColumn: false,
      type: '', //分类
      loginUser: '',
      tableKey: 1.9,
      sessionParams: {},
    }
  },
  computed: {
    scrollX() {
      let xnum = 0
      for (let item of this.columns) {
        xnum += Number(item.width) || 0
      }
      return xnum
    },
    ...mapState({
      collapsed: (state) => state.user.collapsed,
    }),
    realFilterNum() {
      let nums = 0
      for (let key in this.realFilterForm) {
        if (this.realFilterForm[key] != '') {
          nums += 1
        }
      }
      return nums
    },
    filteredNums() {
      let nums = 0
      for (let key in this.filterForm) {
        if (this.filterForm[key] != '') {
          nums += 1
        }
      }
      return nums
    },
    filteredList() {
      // debugger
      let list = []
      for (let key in this.filterForm) {
        if (this.filteredFormLable[key] == '类型') {
          let strArr = ''
          for (let item of this.filterForm[key]) {
            for (let each of this.typeList) {
              if (item == each.value) {
                strArr += each.title + '，'
              }
            }
          }
          strArr = strArr.substring(0, strArr.length - 1)
          list.push({
            title: this.filteredFormLable[key],
            text: strArr,
            key,
          })
        } else if (this.filteredFormLable[key] == '分类') {
          list.push({
            title: this.filteredFormLable[key],
            text: this.treeSelectLael,
            key,
          })
        } else if (this.filteredFormLable[key] == '负责人') {
          list.push({
            title: this.filteredFormLable[key],
            text: this.showPrincipalStr,
            key,
          })
        } else if (this.filteredFormLable[key] == '创建人') {
          list.push({
            title: this.filteredFormLable[key],
            text: this.showCreateStr,
            key,
          })
        } else {
          list.push({
            title: this.filteredFormLable[key],
            text: this.filterForm[key],
            key,
          })
        }
      }
      return list
    },
  },
  created() {
    /* 设置列 */
    var oldValue = localStorage.getItem(this.BUSI_CONST.Entity.GOODS_MANAGEMENT_LIST)
    this.columns = getNewColumns(this.columnsValue, JSON.parse(oldValue), actionArr, this.columns)
    getEnableOne({ id: 'WMS_GOODS', type: 'add' }).then((res) => {
      if (res.result && res.result == 'false') {
        this.columnsValue = this.columnsValue.filter((item) => item.title != '审核状态')
        this.columns = this.columns.filter((item) => item.title != '审核状态')
      }
    })
    let user = localStorage.getItem('pro__Login_Userinfo')
    this.loginUser = JSON.parse(user).value.id
    let sessionObj = sessionStorage.getItem(`${this.BUSI_CONST.Entity.GOODS_MANAGEMENT_LIST}filter`)
    if (sessionObj) {
      let obj = JSON.parse(sessionObj)
      this.filterForm = obj.filterForm
      this.realFilterForm = obj.realFilterForm
      this.tableFilterForm = obj.tableFilterForm
      this.current = obj.current
      this.pageSize = obj.pageSize
      let params = this.formatData()
      this.getData(params)
    } else {
      this.getData()
    }
    this.getDictModel()
    this.getTreeData()
  },
  beforeRouteLeave(to, from, next) {
    if (to.path != '/warehouseManagement/goodsManagement/goodsManagementAdd' || JSON.stringify(to.query) == '{}') {
      sessionStorage.removeItem(`${this.BUSI_CONST.Entity.GOODS_MANAGEMENT_LIST}filter`)
    }
    next()
  },
  methods: {
    treeChange(value, label, extra) {
      this.treeSelectLael = label[0]
    },
    /* 删除、批量删除 */
    handleDelete(v) {
      let params = this.formatData()
      if (v instanceof Array) {
        if (v.length > 0) {
          let that = this
          that.$antdConfirm({
            title: '确定要删除物品吗?',
            content: `共选中${v.length}条物品`,
            onOk() {
              goodsLogicDelBatch({ ids: v.toString() }).then((res) => {
                if (res.code == 200) {
                  that.$antdMessage.success('删除成功！')
                  that.current = 1
                  that.getData(params)
                  that.clearArr()
                } else {
                  that.$antdMessage.error(res.message)
                }
              })
            },
            onCancel() {},
          })
        } else {
          this.$antdMessage.warning('请勾选需要批量删除的数据')
        }
      } else {
        let that = this
        that.$antdConfirm({
          title: '删除后不可恢复',
          content: `确定删除吗？`,
          onOk() {
            goodsLogicDel({ id: v.id }).then((res) => {
              if (res.code == 200) {
                that.$antdMessage.success('删除成功！')
                if (that.tableData.length === 1) {
                  that.current = that.current == 1 ? 1 : that.current - 1
                }
                that.getData(params)
                that.clearArr()
              } else {
                that.$antdMessage.error(res.message)
              }
            })
          },
          onCancel() {},
        })
      }
    },
    /* 撤回 */
    handleWithdraw(v) {
      let that = this
      let params = this.formatData()
      that.$antdConfirm({
        title: '确定撤回吗？',
        content: '撤回后暂不支持再次发起',
        onOk() {
          API.operateRevoke({ flowInstId: v.flowInstId }).then((res) => {
            if (res.code == 200) {
              that.$antdMessage.success(res.message)
              that.current = 1
              that.getData(params)
            } else {
              that.$antdMessage.error(res.message)
            }
          })
        },
        onCancel() {},
      })
    },
    getTreeData() {
      // 取分类树
      categoryGetTree({ code: 'B05' }).then((res) => {
        let arr = res.result
        arr.map((item) => {
          if (item.children.length > 0) {
            item.disabled = true
            ;(function bianli(e = item) {
              e.children.forEach((item) => {
                if (item.children.length > 0) {
                  item.disabled = true
                  bianli(item)
                }
              })
            })()
          }
        })
        this.treeData = arr
      })
    },
    /* 编辑 */
    handleEdit(v) {
      sessionStorage.setItem(
        `${this.BUSI_CONST.Entity.GOODS_MANAGEMENT_LIST}filter`,
        JSON.stringify(this.sessionParams)
      )
      this.$refs.windowForm.initForm(v.id)
    },
    handleDetail(v) {
      this.$refs.windowDetail.initDetail(v.id)
    },
    getData(obj, secondParams) {
      /* 请求列表数据 */
      if (obj) {
        obj.type = obj.type ? `${obj.type},${this.type}` : this.type
      }
      let params = {
        pageNo: this.current,
        pageSize: this.pageSize,
        // type: this.type,
        ...obj,
      }
      this.sessionParams = {
        filterForm: this.filterForm,
        realFilterForm: this.realFilterForm,
        tableFilterForm: this.tableFilterForm,
        current: this.current,
        pageSize: this.pageSize,
      }
      goodsList(params).then((res) => {
        if (res.code == 200) {
          this.tableData = res.result.records
          this.total = res.result.total
        }
      })
    },
    getDictModel() {
      // 类型字典
      let parameters = { dictCode: 'wms_goods_type' }
      getDictModel(parameters).then((res) => {
        if (res.code == 200) {
          var arr = JSON.parse(JSON.stringify(res.result))
          // let arr = res.result
          arr.unshift({
            value: '0',
            title: '全部',
          })
          this.typeListTab = JSON.parse(JSON.stringify(arr))
          console.log(this.typeListTab, 'this.typeListTab')
          this.typeList = JSON.parse(JSON.stringify(res.result))
          console.log(res, 'inStockStatus')
        }
      })
    },
    // 最上面切换检索
    changeCurrent(key) {
      if (key == '0') {
        this.type = ''
      } else {
        this.type = key
      }
      this.current = 1
      let params = this.formatData()
      // params.type = params.type ? `${params.type},${this.type}` : this.type
      console.log(params)
      this.getData(params)
    },
    goBack() {},
    // 点击新建按钮
    add() {
      this.$refs.windowForm.initForm()
    },
    /* 打开设置列面板123 */
    showColumn() {
      this.showSetColumn = true
      this.$nextTick(() => {
        this.$refs.SetColumn.paramsData(this.columnsValue, this.BUSI_CONST.Entity.GOODS_MANAGEMENT_LIST, this.columns)
      })
    },
    /* 设置列 */
    sureBtn(emitArr) {
      this.columns = getNewColumns(this.columnsValue, emitArr, actionArr)
      localStorage.setItem(this.BUSI_CONST.Entity.GOODS_MANAGEMENT_LIST, JSON.stringify(emitArr))
      this.tableKey += 1
    },
    // 列头检索提示语
    checkPlaceholder(dataIndex) {
      let str = ''
      switch (dataIndex) {
        case 'goodsCode':
          str = '请输入物品编号'
          break
        case 'goodsName':
          str = '请输入物品名称'
          break
        case 'category':
          str = '请选择分类'
          break
        case 'type':
          str = '请选择类型'
          break
        case 'spec':
          str = '请输入规格'
          break
      }
      return str
    },
    // 列头检索
    pubSearch(confirm, dataIndex, clearFilters) {
      confirm() //用来关闭搜索弹窗
      // clearFilters() //用来重置搜索内容
      this.filterForm = JSON.parse(JSON.stringify(this.tableFilterForm))
      this.realFilterForm = JSON.parse(JSON.stringify(this.tableFilterForm))
      let params = this.formatData()
      this.current = 1
      let obj = {
        pageNo: this.current,
        pageSize: this.pageSize,
        ...params,
      }
      this.getData(obj)
    },
    // table
    tableChange(pagination, filters, sorter, { currentDataSource }) {
      let params = this.formatData()
      if (sorter.order) {
        let sortType = ''
        if (sorter.order == 'ascend') {
          sortType = 'ASC'
        } else {
          sortType = 'DESC'
        }
        let obj = {
          pageNo: this.current,
          pageSize: this.pageSize,
          ...params,
          sortType: sortType,
          sortColumn: sorter.columnKey,
        }
        this.getData(obj)
      } else {
        let obj = {
          pageNo: this.current,
          pageSize: this.pageSize,
          ...params,
        }
        this.getData(obj)
      }
    },
    // 筛选
    /* 打开筛选 */
    handleShowFilter() {
      this.filterForm = JSON.parse(JSON.stringify(this.realFilterForm))
      this.showFilter = true
    },
    /* 重置筛选 */
    resetFilter() {
      this.filterForm = {
        goodsCode: '', //物品编号
        goodsName: '', //物品名称
        category: [], //分类
        type: [], //类型
        spec: '', //规格
        // flowStatus: [], //审核状态
      }
      this.treeSelectLael = ''
      this.handleFilter()
    },
    //更新父组件页面
    updateParentData() {
      let params = this.formatData()
      this.current = 1
      let obj = {
        pageNo: this.current,
        pageSize: this.pageSize,
        ...params,
      }
      this.getData(obj)
    },
    /* 确定筛选 */
    handleFilter() {
      let params = this.formatData()
      this.current = 1
      let obj = {
        pageNo: this.current,
        pageSize: this.pageSize,
        ...params,
      }
      this.getData(obj)
      this.realFilterForm = JSON.parse(JSON.stringify(this.filterForm))
      this.tableFilterForm = JSON.parse(JSON.stringify(this.filterForm))
      this.showFilter = false
    },
    // 筛选传参数据
    formatData() {
      let copyForm = JSON.parse(JSON.stringify(this.filterForm))
      let params = {}
      // if (copyForm.category && copyForm.category.length > 0) {
      //   params.category = copyForm.category
      // } else {
      //   params.category = ''
      // }
      if (copyForm.type && copyForm.type.length > 0) {
        params.type = copyForm.type.join(',')
      } else {
        params.type = ''
      }
      // if (copyForm.flowStatus && copyForm.flowStatus.length > 0) {
      //   params.flowStatus = copyForm.flowStatus.join(',')
      // } else {
      //   params.flowStatus = ''
      // }
      params.category = copyForm.category
      params.goodsCode = copyForm.goodsCode
      params.goodsName = copyForm.goodsName
      params.spec = copyForm.spec
      return params
    },
    checkShow(item) {
      let currentBoolean = Array.isArray(item)
      if (currentBoolean) {
        if (item.length == 0) {
          return false
        } else {
          return true
        }
      } else {
        if (item) {
          return true
        } else {
          return false
        }
      }
    },
    /* 删除已选 */
    delFiltered(key) {
      if (this.filteredFormLable[key] == '物品编号') {
        this.filterForm[key] = []
      } else if (this.filteredFormLable[key] == '物品名称') {
        this.filterForm[key] = []
      } else if (this.filteredFormLable[key] == '分类') {
        this.filterForm[key] = []
        this.treeSelectLael = ''
      } else if (this.filteredFormLable[key] == '类型') {
        this.filterForm[key] = []
      } else if (this.filteredFormLable[key] == '审核状态') {
        this.filterForm[key] = []
      } else {
        this.filterForm[key] = ''
      }
    },
    /* 关闭筛选 */
    closeFilter() {
      this.showFilter = false
    },
    filterNumChang(value) {
      this.filteredNums = value
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.checkBoxStatus()
    },
    checkBoxStatus() {
      if (this.selectedRowKeys.length == 0) {
        this.listIndeterminate = false
        this.listCheckAll = false
      } else {
        let tableIds = []
        for (let item of this.tableData) {
          tableIds.push(item.id)
        }
        let checkValue = this.isInclude(tableIds, this.selectedRowKeys)
        if (checkValue) {
          this.listIndeterminate = false
          this.listCheckAll = true
        } else {
          this.listIndeterminate = true
          this.listCheckAll = false
        }
      }
    },
    isInclude(aa, bb) {
      return aa.every((item) => {
        return bb.some((sub) => {
          return sub === item
        })
      })
    },
    // 全选
    onCheckAllChange(e) {
      if (e.target.checked) {
        for (let item of this.tableData) {
          this.selectedRowKeys.push(item.id)
        }
      } else {
        for (let item of this.tableData) {
          this.selectedRowKeys = this.selectedRowKeys.filter((each) => {
            return each != item.id
          })
        }
      }
      this.checkBoxStatus()
    },
    clearArr() {
      this.selectedRowKeys = []
      this.checkBoxStatus()
    },
    // 分页
    onChangePage(current, pageSize) {
      this.current = current
      let params = this.formatData()
      this.getData(params)
    },
    onShowSizeChange(current, pageSize) {
      this.pageSize = pageSize
      this.current = current
      let params = this.formatData()
      this.getData(params)
    },
  },
}
</script>
<style scoped lang="less">
@import '~@/assets/less/public.less';
.flex(@jc,@ai,@fd:row) {
  display: flex;
  justify-content: @jc;
  align-items: @ai;
  flex-direction: @fd;
}
.table-operations {
  margin-bottom: 16px;
}

.table-operations > button {
  margin-right: 8px;
}
.topBox {
  .flex(space-between, center);
  margin-bottom: 16px;
}
.searchWorkOreder {
  .flex(flex-start, center);
  padding: 8px;
}
.pubColor {
  font-size: 14px;
  color: #1890ff;
  cursor: pointer;
}
.pagebox {
  /deep/ .ant-card-body {
    height: calc(100vh - 214px);
    overflow: hidden;
    padding: 20px 16px;
  }
}
.filter-tit {
  background: #fff;
  border-bottom: 1px solid @greyBorder;
  font-size: @fontSize4;
}
.filter-num {
  color: @normalFont;
}
.filter-body {
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.margin-btn {
  margin-right: @distance5;
}
.filter-tag {
  display: inline-block;
  position: relative;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: @fontSize1;
  line-height: @fontSize1;
  max-width: 100%;
  background: @greyBg;
  color: @titFont;
  cursor: pointer;
  .tag-text {
    display: inline-block;
    padding-right: 20px;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .anticon-close {
    position: absolute;
    right: 8px;
    top: 8px;
  }
}
.tag-wrap:nth-of-type(n + 2) {
  margin-top: 10px;
}
.searchWorkOreder {
  .flex(flex-start, center);
  padding: 8px;
}
.modalTopBox {
  .flex(flex-start, center);
  margin-bottom: 8px;
  span {
    margin-left: 16px;
    display: block;
    overflow: hidden;
    color: rgba(0, 0, 0, 0.85);
    font-weight: 500;
    font-size: 16px;
    line-height: 1.4;
  }
}
.bigFont {
  font-size: 16px;
  color: rgba(0, 0, 0, 0.78);
  box-sizing: border-box;
  padding-left: 12px;
  margin-bottom: 8px;
  font-weight: 600;
}
.smallFont {
  font-size: 14px;
  box-sizing: border-box;
  padding-left: 12px;
}
</style>
